package top.xiangqifu.springboot2.user.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;
import top.xiangqifu.springboot2.user.base.BasePageResult;
import top.xiangqifu.springboot2.user.base.BaseResult;
import top.xiangqifu.springboot2.user.base.PageBean;
import top.xiangqifu.springboot2.user.entity.TbUser;
import top.xiangqifu.springboot2.user.service.AuthService;
import top.xiangqifu.springboot2.user.service.UserInfoService;
import top.xiangqifu.springboot2.user.vo.UserInfo;

import java.util.List;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Api(tags = "用户信息相关接口")
public class UserController {

    private final AuthService authService;

    @ApiOperation(value ="冻结的用户",notes = "查询冻结用户功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "登录用户名",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "deleted",value = "逻辑删除标记",dataTypeClass = String.class ,required = true),
    })
    @GetMapping("")
    public BasePageResult<List<TbUser>> queryDelete(PageBean pageBean, String deleted) {
        return authService.queryDelete(deleted,pageBean);
    }

    @ApiOperation(value ="冻结用户",notes = "冻结用户功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @DeleteMapping("/{uid}")
    public BaseResult delete(@PathVariable("uid") Integer uid){
        return authService.delete(uid);
    }

    @ApiOperation(value ="解除冻结",notes = "解除冻结功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deleted",value = "逻辑删除标记",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @PutMapping("/{uid}")
    public BaseResult update(@RequestBody TbUser tbUser, @PathVariable("uid") Integer uid){
        tbUser.setUid(uid);
        return authService.update(tbUser);
    }

    @ApiOperation(value ="用户注册",notes = "用户注册功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "用户账号",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "password",value = "用户密码",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @PostMapping("")
    public BaseResult reg(@RequestBody TbUser tbUser){
        return authService.reg(tbUser);
    }
}
